package com.zz.springcloud.controller;

import com.zz.springcloud.entity.Member;
import com.zz.springcloud.util.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/member/consumer")
public class MemberConsumerController {
//    public static final String MEMBER_SERVICE_PROVIDER_URL = "http://localhost:6999";
    public static final String MEMBER_SERVICE_PROVIDER_URL = "http://member-service-nacos-provider";
    @Resource
    private RestTemplate restTemplate;

    @PostMapping("/save")
    public Result<Member> save(Member member){
        return restTemplate.postForObject(MEMBER_SERVICE_PROVIDER_URL
                + "/member/save", member, Result.class);
    }

    @GetMapping("/get/{id}")
    public Result<Member> getMemberById(@PathVariable("id") Long id) {
        return restTemplate.getForObject(MEMBER_SERVICE_PROVIDER_URL
                + "/member/get/" + id, Result.class);
    }
}
